var csInterface = new CSInterface();

// 个人主页
var homePageElement = document.querySelector("#homePage");
homePageElement.addEventListener("click", callHomepage);

function callHomepage() {
  window.cep.util.openURLInDefaultBrowser('https://gitee.com/brzjomo');
}

// 调用排序函数
var runButtonLengthenLeft = document.querySelector("#btn-left");
var runButtonLengthenRight = document.querySelector("#btn-right");
var runButtonLengthenUp = document.querySelector("#btn-up");
var runButtonLengthenDown = document.querySelector("#btn-down");
var runButtonLengthenCenter = document.querySelector("#btn-center");
runButtonLengthenLeft.addEventListener("click", lengthenLeft);
runButtonLengthenRight.addEventListener("click", lengthenRight);
runButtonLengthenUp.addEventListener("click", lengthenUp);
runButtonLengthenDown.addEventListener("click", lengthenDown);
runButtonLengthenCenter.addEventListener("click", lengthenCenter);

function lengthenLeft() {
  // 获取宽幅
  var materialWidthElement = document.getElementById("material-width");
  var materialWidth = parseFloat(materialWidthElement.options[materialWidthElement.selectedIndex].value);
  // 获取制图比例
  var drawingScaleElement = document.getElementById("drawing-scale");
  var drawingScale = parseInt(drawingScaleElement.options[drawingScaleElement.selectedIndex].value);

  var direction = 4;
  var value = parseInt(document.getElementsByName("text-input")[0].value);

  csInterface.evalScript('lengthen(' + materialWidth + ', ' + drawingScale + ', ' + direction + ', ' + value +')');
}

function lengthenRight() {
  // 获取宽幅
  var materialWidthElement = document.getElementById("material-width");
  var materialWidth = parseFloat(materialWidthElement.options[materialWidthElement.selectedIndex].value);
  // 获取制图比例
  var drawingScaleElement = document.getElementById("drawing-scale");
  var drawingScale = parseInt(drawingScaleElement.options[drawingScaleElement.selectedIndex].value);

  var direction = 6;
  var value = parseInt(document.getElementsByName("text-input")[0].value);

  csInterface.evalScript('lengthen(' + materialWidth + ', ' + drawingScale + ', ' + direction + ', ' + value +')');
}

function lengthenUp() {
  // 获取宽幅
  var materialWidthElement = document.getElementById("material-width");
  var materialWidth = parseFloat(materialWidthElement.options[materialWidthElement.selectedIndex].value);
  // 获取制图比例
  var drawingScaleElement = document.getElementById("drawing-scale");
  var drawingScale = parseInt(drawingScaleElement.options[drawingScaleElement.selectedIndex].value);

  var direction = 8;
  var value = parseInt(document.getElementsByName("text-input")[0].value);

  csInterface.evalScript('lengthen(' + materialWidth + ', ' + drawingScale + ', ' + direction + ', ' + value +')');
}

function lengthenDown() {
  // 获取宽幅
  var materialWidthElement = document.getElementById("material-width");
  var materialWidth = parseFloat(materialWidthElement.options[materialWidthElement.selectedIndex].value);
  // 获取制图比例
  var drawingScaleElement = document.getElementById("drawing-scale");
  var drawingScale = parseInt(drawingScaleElement.options[drawingScaleElement.selectedIndex].value);

  var direction = 2;
  var value = parseInt(document.getElementsByName("text-input")[0].value);

  csInterface.evalScript('lengthen(' + materialWidth + ', ' + drawingScale + ', ' + direction + ', ' + value +')');
}

function lengthenCenter() {
  // 获取宽幅
  var materialWidthElement = document.getElementById("material-width");
  var materialWidth = parseFloat(materialWidthElement.options[materialWidthElement.selectedIndex].value);
  // 获取制图比例
  var drawingScaleElement = document.getElementById("drawing-scale");
  var drawingScale = parseInt(drawingScaleElement.options[drawingScaleElement.selectedIndex].value);

  var direction = 5;
  var value = parseInt(document.getElementsByName("text-input")[0].value);

  csInterface.evalScript('lengthen(' + materialWidth + ', ' + drawingScale + ', ' + direction + ', ' + value +')');
}
